

//
//  CommentTableViewCell.m
//  News
//
//  Created by xalo on 16/3/7.
//  Copyright © 2016年 News. All rights reserved.
//

#import "CommentTableViewCell.h"
#import "CommentModel.h"
#import <UIImageView+WebCache.h>

@implementation CommentTableViewCell

-(void)setCommModel:(CommentModel *)commModel {
    
    _commModel = commModel;
    [self.urlIMage sd_setImageWithURL:[NSURL URLWithString:commModel.wb_profile_img]];
    
    [self.urlIMage layoutIfNeeded];
    self.urlIMage.layer.cornerRadius = CGRectGetHeight(self.urlIMage.frame)/2;
    self.urlIMage.layer.masksToBounds =YES;
    
    self.nickLA.text = commModel.nick;
    self.timeLA.text = [self changeDateToStringWithModel:commModel];
    self.comtentLA.text = commModel.content;
    
    CGFloat height = [CommentTableViewCell heightForString:commModel.content];
    if (height > 30) {
        CGRect frame = self.comtentLA.frame;
        frame.size.height =height;
        self.comtentLA.frame =frame;
    }
    
    self.areLA.text = commModel.area;
    self.agree.text = commModel.agree;
    
    
}

+(CGFloat)heightForString:(NSString *)string {
    
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName];
    
    CGFloat weith = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat cellWith = weith - 40;
    CGRect bound = [string boundingRectWithSize:CGSizeMake(cellWith, 2000) options:(NSStringDrawingUsesLineFragmentOrigin)attributes:dic context:nil];
    
    return bound.size.height;
}





-(NSString *)changeDateToStringWithModel:(CommentModel *)model {
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:model.time];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString *string = [formatter stringFromDate:date];
    
    return string;
    
}





@end
